Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
os: windows store下的Ubuntu20.04
gcc version: 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
初始运行时间:1220ms
优化:
1. -ffast-math -march=native
2. SOA替换AOS
3. 循环的i修改为size_t
4. 使用std下的数学函数
5. 乘法替换除法
6. 热代码计算部分的常量都提前计算好再放入循环中
7. #pragma GCC unroll 效果不大
最终优化时间:128ms
在修改后的代码基础上,只修改Star,修改为std::array,速度就变为700+ms了,没做详细研究
感谢小彭老师,年轻人的第一次优化